package cn.buk.tms.eotms.dto;

import cn.buk.tms.common.dto.base.BaseOrderDto;
import cn.buk.tms.eotms.entity.RentalCarOrder;
import cn.buk.tms.eotms.util.OrderUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 租车订单
 * @author yfdai
 */
public class CarOrderDto extends BaseOrderDto {

  /**
   * 联系人
   */
  private String linkman;
  /**
   * 联系电话
   */
  private String linkPhone;
  /**
   * 联系电子邮件
   */
  private String email;

  /**
   * 相关联的机票订单id
   */
  private int flightOrderId;

  public static CarOrderDto createByRentalCarOrder(RentalCarOrder o) {
    CarOrderDto dto = new CarOrderDto();

    BeanUtils.copyProperties(o, dto);

    //审批相关信息
    OrderUtil.copyApprovalInfo(o.getApprovalInfo(), dto);


    dto.setLinkman(o.getName());
    dto.setLinkPhone(o.getMobile());
    dto.setOrderStatus(o.getStatus());

    dto.calc();

    return dto;
  }

  private void calc() {
    this.totalAmount = this.getPrice() - this.discount;
    //控制小数点位数
    this.totalAmount = BigDecimal.valueOf(this.totalAmount).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  }

  /**
   * 用车类型
   * 1-接飞机，2-送飞机，3-接火车，4-送火车
   */
  private int useType;
  /**
   * 用车城市
   */
  private int cityId;
  /**
   * 城市名
   */
  @JsonInclude(JsonInclude.Include.NON_NULL)
  private String cityName;
  /**
   * 接送的机场代码
   */
  private String airportCode;
  /**
   * 航班号
   */
  private String flightNo;
  /**
   * 出发地址
   */
  private String departureAddress;
  /**
   * 到达地址
   */
  private String arrivalAddress;


  /**
   * 用车时间
   */
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
  private Date useTime;
  /**
   * 订单状态
   */
  private int status;
  /**
   * 车型组名称
   */
  @JsonInclude(JsonInclude.Include.NON_NULL)
  private String vehicleTypeName;
  /**
   * 价格
   */
  private Double price;
  /**
   * 优惠金额
   */
  private double discount;
  /**
   * 总金额
   */
  private double totalAmount;
  /**
   * 备注
   */
  private String remark;



  public int getUseType() {
    return useType;
  }

  public void setUseType(int useType) {
    this.useType = useType;
  }

  public int getCityId() {
    return cityId;
  }

  public void setCityId(int cityId) {
    this.cityId = cityId;
  }

  public String getAirportCode() {
    return airportCode;
  }

  public void setAirportCode(String airportCode) {
    this.airportCode = airportCode;
  }

  public String getDepartureAddress() {
    return departureAddress;
  }

  public void setDepartureAddress(String departureAddress) {
    this.departureAddress = departureAddress;
  }

  public String getArrivalAddress() {
    return arrivalAddress;
  }

  public void setArrivalAddress(String arrivalAddress) {
    this.arrivalAddress = arrivalAddress;
  }

  public Date getUseTime() {
    return useTime;
  }

  public void setUseTime(Date useTime) {
    this.useTime = useTime;
  }



  public String getCityName() {
    return cityName;
  }

  public void setCityName(String cityName) {
    this.cityName = cityName;
  }

  public int getStatus() {
    return status;
  }

  public void setStatus(int status) {
    this.status = status;
  }

  public String getFlightNo() {
    return flightNo;
  }

  public void setFlightNo(String flightNo) {
    this.flightNo = flightNo;
  }


  public String getVehicleTypeName() {
    return vehicleTypeName;
  }

  public void setVehicleTypeName(String vehicleTypeName) {
    this.vehicleTypeName = vehicleTypeName;
  }

  public void setLinkman(String linkman) {
    this.linkman = linkman;
  }

  public String getLinkman() {
    return linkman;
  }

  public void setLinkPhone(String linkPhone) {
    this.linkPhone = linkPhone;
  }

  public String getLinkPhone() {
    return linkPhone;
  }

  public double getPrice() {
    return price == null ? 0 : price;
  }

  public void setPrice(Double price) {
    this.price = price;
  }

  public String getRemark() {
    return remark;
  }

  public void setRemark(String remark) {
    this.remark = remark;
  }

  public Double getDiscount() {
    return discount;
  }

  public void setDiscount(Double discount) {
    this.discount = discount;
  }

  public String getEmail() {
    return email;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  public Double getTotalAmount() {
    return totalAmount;
  }

  public void setTotalAmount(Double totalAmount) {
    this.totalAmount = totalAmount;
  }

  public int getFlightOrderId() {
    return flightOrderId;
  }

  public void setFlightOrderId(int flightOrderId) {
    this.flightOrderId = flightOrderId;
  }
}

